*===================================================================================*
* Ado-file: 	CyberFT Version 1.0 
* Author: 		Shutter Zor(左祥太)
* Affiliation: 	Accounting Department, Xiamen University
* E-mail: 		Shutter_Z@outlook.com 
* Date: 		2025/2/24                                       
*===================================================================================*



capture program drop cyberft
program define cyberft
	version 13
	
	syntax, Question(string)
	
	*- status randomization
	tokenize "`c(current_date)'"

	local year_ratio = `3' / 9999

	if ("`2'" == "Jan") | ("`2'" == "Mar") | ("`2'" == "May") | ("`2'" == "Jul") | ("`2'" == "Aug") | ("`2'" == "Oct") | ("`2'" == "Dec") {
		local month = 1
		local month_ratio = `month' / 12
		local day_ratio = `1' / 31
	}

	if ("`2'" == "Apr") | ("`2'" == "Jun") | ("`2'" == "Sep") | ("`2'" == "Nov") {
		local month = 3
		local month_ratio = `month' / 12
		local day_ratio = `1' / 30
	}

	if ("`2'" == "Feb") & (mod(`3',4) == 0) {
		local month = 2
		local month_ratio = `month' / 12
		local day_ratio = `1' /29
	}

	if ("`2'" == "Feb") & (mod(`3',4) != 0) {
		local month = 2
		local month_ratio = `month' / 12
		local day_ratio = `1' /28
	}

	tokenize "`c(current_time)'", parse(":")
	local hour_ratio = `1' / 24
	local minute_ratio = `3' / 60
	local second_ratio = `5' / 60

	*- softmax, range = [1, 163]
	local softmax_denominator = exp(`year_ratio') + exp(`month_ratio') + exp(`day_ratio') + exp(`hour_ratio') + exp(`minute_ratio') + exp(`second_ratio')
	local softmax_year = exp(`year_ratio') / `softmax_denominator'
	local softmax_month = exp(`month_ratio') / `softmax_denominator'
	local softmax_day = exp(`day_ratio') / `softmax_denominator'
	local softmax_hour = exp(`hour_ratio') / `softmax_denominator'
	local softmax_minute = exp(`minute_ratio') / `softmax_denominator'
	local softmax_second = exp(`second_ratio') / `softmax_denominator'
	local answer_probation = max(`softmax_year', `softmax_month', `softmax_day', `softmax_hour', `softmax_minute', `softmax_second')
	local answer_number = mod(floor(`answer_probation'*100000000), 163) + 1
	
	*- write answer file
	preserve
		cap use "`c(sysdir_plus)'/c/cyberft_answer.dta", clear
		if _rc != 0 {
			dis "检测到当前未加载答案结果文件，正在从Gitee下载答案结果文件。。。"
			copy "https://gitee.com/Shutter_Zor/cyberft/raw/master/cyberft_answer.dta" "`c(sysdir_plus)'/c/cyberft_answer.dta"
			dis "下载完成，本过程仅在第一次使用时加载。"
		}
	restore
	
	*- answer randomization
	preserve
		use "`c(sysdir_plus)'/c/cyberft_answer.dta", clear
		gen id = runiform()
		sort id
		local answer = answer[`answer_number']
	restore
	
	*- display answer
	dis " "
	dis as result "`answer'"
	
end


